<%@page pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html lang="zh-CN">
  <head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <meta name="author" content="">

	<link rel="stylesheet" href="${APP_PATH}/bootstrap/css/bootstrap.min.css">
	<link rel="stylesheet" href="${APP_PATH}/css/font-awesome.min.css">
	<link rel="stylesheet" href="${APP_PATH}/css/main.css">
	<style>
	.tree li {
        list-style-type: none;
		cursor:pointer;
	}
	table tbody tr:nth-child(odd){background:#F4F4F4;}
	table tbody td:nth-child(even){color:#C00;}
	</style>
  </head>

  <body>

    <nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
      <div class="container-fluid">
        <div class="navbar-header">
          <div><a class="navbar-brand" style="font-size:32px;" href="#">众筹平台 - 用户维护</a></div>
        </div>
        <div id="navbar" class="navbar-collapse collapse">
          <ul class="nav navbar-nav navbar-right">
            <li style="padding-top:8px;">
				<div class="btn-group">
				  <button type="button" class="btn btn-default btn-success dropdown-toggle" data-toggle="dropdown">
					<i class="glyphicon glyphicon-user"></i> 张三 <span class="caret"></span>
				  </button>
					  <ul class="dropdown-menu" role="menu">
						<li><a href="#"><i class="glyphicon glyphicon-cog"></i> 个人设置</a></li>
						<li><a href="#"><i class="glyphicon glyphicon-comment"></i> 消息</a></li>
						<li class="divider"></li>
						<li><a href="index.html"><i class="glyphicon glyphicon-off"></i> 退出系统</a></li>
					  </ul>
			    </div>
			</li>
            <li style="margin-left:10px;padding-top:8px;">
				<button type="button" class="btn btn-default btn-danger">
				  <span class="glyphicon glyphicon-question-sign"></span> 帮助
				</button>
			</li>
          </ul>
          <form class="navbar-form navbar-right">
            <input type="text" class="form-control" placeholder="Search...">
          </form>
        </div>
      </div>
    </nav>

    <div class="container-fluid">
      <div class="row">
        <div class="col-sm-3 col-md-2 sidebar">
			<div class="tree">
				<ul style="padding-left:0px;" class="list-group">
					<li class="list-group-item tree-closed" >
						<a href="main.html"><i class="glyphicon glyphicon-dashboard"></i> 控制面板</a>
					</li>
					<li class="list-group-item">
						<span><i class="glyphicon glyphicon glyphicon-tasks"></i> 权限管理 <span class="badge" style="float:right">3</span></span>
						<ul style="margin-top:10px;">
							<li style="height:30px;">
								<a href="user.html" style="color:red;"><i class="glyphicon glyphicon-user"></i> 用户维护</a>
							</li>
							<li style="height:30px;">
								<a href="role.html"><i class="glyphicon glyphicon-king"></i> 角色维护</a>
							</li>
							<li style="height:30px;">
								<a href="permission.html"><i class="glyphicon glyphicon-lock"></i> 许可维护</a>
							</li>
						</ul>
					</li>
					<li class="list-group-item tree-closed">
						<span><i class="glyphicon glyphicon-ok"></i> 业务审核 <span class="badge" style="float:right">3</span></span>
						<ul style="margin-top:10px;display:none;">
							<li style="height:30px;">
								<a href="auth_cert.html"><i class="glyphicon glyphicon-check"></i> 实名认证审核</a>
							</li>
							<li style="height:30px;">
								<a href="auth_adv.html"><i class="glyphicon glyphicon-check"></i> 广告审核</a>
							</li>
							<li style="height:30px;">
								<a href="auth_project.html"><i class="glyphicon glyphicon-check"></i> 项目审核</a>
							</li>
						</ul>
					</li>
					<li class="list-group-item tree-closed">
						<span><i class="glyphicon glyphicon-th-large"></i> 业务管理 <span class="badge" style="float:right">7</span></span>
						<ul style="margin-top:10px;display:none;">
							<li style="height:30px;">
								<a href="cert.html"><i class="glyphicon glyphicon-picture"></i> 资质维护</a>
							</li>
							<li style="height:30px;">
								<a href="type.html"><i class="glyphicon glyphicon-equalizer"></i> 分类管理</a>
							</li>
							<li style="height:30px;">
								<a href="process.html"><i class="glyphicon glyphicon-random"></i> 流程管理</a>
							</li>
							<li style="height:30px;">
								<a href="advertisement.html"><i class="glyphicon glyphicon-hdd"></i> 广告管理</a>
							</li>
							<li style="height:30px;">
								<a href="message.html"><i class="glyphicon glyphicon-comment"></i> 消息模板</a>
							</li>
							<li style="height:30px;">
								<a href="project_type.html"><i class="glyphicon glyphicon-list"></i> 项目分类</a>
							</li>
							<li style="height:30px;">
								<a href="tag.html"><i class="glyphicon glyphicon-tags"></i> 项目标签</a>
							</li>
						</ul>
					</li>
					<li class="list-group-item tree-closed" >
						<a href="param.html"><i class="glyphicon glyphicon-list-alt"></i> 参数管理</a>
					</li>
				</ul>
			</div>
        </div>
        <div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">
			<div class="panel panel-default">
			  <div class="panel-heading">
				<h3 class="panel-title"><i class="glyphicon glyphicon-th"></i> 数据列表</h3>
			  </div>
			  <div class="panel-body">
<form class="form-inline" role="form" style="float:left;">
  <div class="form-group has-feedback">
    <div class="input-group">
      <div class="input-group-addon">查询条件</div>
      <input id="queryText" class="form-control has-success" type="text" placeholder="请输入查询条件">
    </div>
  </div>
  <button type="button" id="queryBtn" class="btn btn-warning"><i class="glyphicon glyphicon-search"></i> 查询</button>
</form>
<button type="button" onclick="batchDelete()" class="btn btn-danger" style="float:right;margin-left:10px;"><i class=" glyphicon glyphicon-remove"></i> 删除</button>
<button type="button" class="btn btn-primary" style="float:right;" onclick="window.location.href='${APP_PATH}/user/add'"><i class="glyphicon glyphicon-plus"></i> 新增</button>
<br>
 <hr style="clear:both;">
          <div class="table-responsive">
			  <form id="batchCheck">
            <table class="table  table-bordered">
              <thead>
                <tr >
                  <th width="30">#</th>
				  <th width="30"><input type="checkbox" id = "allSelectBox"></th>
                  <th>账号</th>
                  <th>名称</th>
                  <th>邮箱地址</th>
                  <th width="100">操作</th>
                </tr>
              </thead>
              <tbody id="userData">
              </tbody>
			  <tfoot>
			     <tr >
				     <td colspan="6" align="center">
						<ul class="pagination">
							 </ul>
					 </td>
				 </tr>

			  </tfoot>
            </table>
			  </form>
          </div>
			  </div>
			</div>
        </div>
      </div>
    </div>

    <script src="${APP_PATH}/jquery/jquery-2.1.1.min.js"></script>
    <script src="${APP_PATH}/bootstrap/js/bootstrap.min.js"></script>
	<script src="${APP_PATH}/script/docs.min.js"></script>
	<script src="${APP_PATH}/layer/layer.js"></script>
        <script type="text/javascript">

			var likeflg = false;

            $(function () {

            	$('#allSelectBox').click(function () {
            		var flg = this.checked;
            		$("#userData :checkbox").each(function () {
            			this.checked = flg;

					})

				})


			    $(".list-group-item").click(function(){
				    if ( $(this).find("ul") ) {
						$(this).toggleClass("tree-closed");
						if ( $(this).hasClass("tree-closed") ) {
							$("ul", this).hide("fast");
						} else {
							$("ul", this).show("fast");
						}
					}
				});
			    //初始化页面时加载数据
				pageQuery(1);

				$('#queryBtn').click(function () {
					var queryText = $('#queryText').val();
					console.log(queryText)
					if (queryText != "" && queryText != null) {
						likeflg = true;
					}

					pageQuery(1)
				})
            });

            $("tbody .btn-success").click(function(){
                window.location.href = "assignRole.html";
            });
            $("tbody .btn-primary").click(function(){
                window.location.href = "edit.html";
            });

            // 使用ajax分页查询
			function pageQuery(pageNo) {
				var loadingIndex = null;

				var jsonData = {
					"pageNo" : pageNo,
					"pageSize" : 4
				}

				//如果文本框不为空则使用查询条件
				if (likeflg) {
					jsonData.lastName = $('#queryText').val();
				}

				$.ajax({
					type : "POST",
					url : "${APP_PATH}/user/ajaxPage",
					data : jsonData,
					beforeSend : function () {
						loadingIndex = layer.msg('处理中', {icon : 16});
					},
					success : function (result) {
						if (result.success) {
							var tableContent = "";
							var pageContent = "";

							var page = result.data;
							var employees = page.datas;
							console.log(employees)
							console.log(page)


							$.each(employees,function (i, emp) {
									tableContent += '<tr >';
									tableContent += '	<td width="30">'+(i + 1)+'</td>';
									tableContent += '	<td width="30"><input type="checkbox" name="employeeIds" value="'+emp.id+'" ></td>';
									tableContent += '	<td>'+emp.id+'</td>';
									tableContent += '	<td>'+emp.lastName+'</td>';
									tableContent += '	<td>'+emp.email+'</td>';
									tableContent += '	<td>';
									tableContent += '      <button type="button" onclick="goAssignPremission('+emp.id+')" class="btn btn-success btn-xs"><i class=" glyphicon glyphicon-search"></i></button>';
									tableContent += '      <button type="button" onclick="goAssignPage('+emp.id+')" class="btn btn-success btn-xs"><i class=" glyphicon glyphicon-check"></i></button>';
									tableContent += '      <button type="button" onclick="goUpdatePage('+emp.id+')" class="btn btn-primary btn-xs"><i class=" glyphicon glyphicon-pencil"></i></button>';
									tableContent += '	  <button type="button" onclick="deleteUser('+emp.id+', \''+emp.lastName+'\')" class="btn btn-danger btn-xs"><i class=" glyphicon glyphicon-remove"></i></button>';
									tableContent += '	</td>';
									tableContent += '</tr>';
							})

							pageContent += '<li><a href="javascript:;" onclick="pageQuery('+page.prevPage+')">上一页</a></li>';
							for (var i = 1; i <= page.totalPage; i++) {
								if (page.pageNo == i){
									pageContent += '<li class="active"><a href="javascript:;" >'+i+'</a></li>';
								} else {
									pageContent += '<li><a href="javascript:;" onclick="pageQuery('+i+')">'+i+'</a></li>';
								}
							}
							pageContent += '<li><a href="javascript:;" onclick="pageQuery('+page.nextPage+')">下一页</a></li>';

							/*if (page.pageNo > 1) {
								pageContent += '<li><a href="?pageNo=' + page.pageNo - 1 + '">上一页</a></li>';
							}


							if (page.pageNo < page.totalPage) {
								pageContent += '<li><a href="?pageNo=' + page.pageNo +1 + '">上一页</a></li>';
							}*/

							console.log(tableContent)
							console.log(pageContent)
							$("#userData").html(tableContent);
							$(".pagination").html(pageContent);

							layer.close(loadingIndex);
						} else {
							layer.close(loadingIndex);
							layer.msg("分页数据失败!",{time : 2000, icon : 5, shift : 6}, function () {

							})
						}

					}

				})
			}

			function goUpdatePage(empId) {
				window.location.href = "${APP_PATH}/user/edit?id="+empId+"";
			}

			function goAssignPage(id) {
				window.location.href = "${APP_PATH}/user/assign?employeeid="+id;
			}

			function goAssignPremission(id) {
				window.location.href = "${APP_PATH}/permission/assign?id="+id;
			}

			function deleteUser(id,lastName) {
				layer.confirm('是否删除'+lastName+'?',{icon:3, title:'提示'},function (cindex) {
					$.ajax({
						type : 'POST',
						url : '${APP_PATH}/user/delete',
						data : {id : id},
						success : function (result) {
							if (result.success) {
								pageQuery(1);
							} else {
								layer.msg("删除用户失败!",{time : 2000, icon : 5, shift : 6}, function () {

								})
							}
						}
					})
					layer.close(cindex);
				},function (cindex) {
					layer.close(cindex);
				})
			}

			function batchDelete() {
				var checkers = $("#userData :checked");
				console.log(checkers + $('#batchCheck').serialize());
				if(checkers.length == 0) {
					layer.msg("请选择要删除的!",{time : 2000, icon : 4, shift : 6}, function () {

					})
					return;
				}
				layer.confirm('是否删除'+$('#batchCheck').serialize()+'?',{icon:3, title:'提示'},function (cindex) {
					$.ajax({
						type : 'POST',
						url : '${APP_PATH}/user/deletes',
						data : $('#batchCheck').serialize(),
						success : function (result) {
							if (result.success) {
								pageQuery(1);
							} else {
								layer.msg("删除失败!",{time : 2000, icon : 5, shift : 6}, function () {

								})
							}
						}
					})
					layer.close(cindex);
				},function (cindex) {
					layer.close(cindex);
				})

			}
        </script>
  </body>
</html>
